from rest_framework import filters

from todo_business.models import TodoTask


class IsOwnerFilterBackend(filters.BaseFilterBackend):
    """
    只允许用户查看他们自己的待办清单
    """

    def filter_queryset(self, request, queryset, view):
        # is_share= request.query_params.get("is_share")
        # if  is_share:
        #     queryset = queryset.filter(len(share_list)
        # else:
        queryset = queryset.filter(author=request.user)

        if 'pk' in request.parser_context['kwargs']:
            id = request.parser_context['kwargs']['pk']
            if id is not None:
                queryset = queryset.filter(id=id)
                # return queryset.first()

        return queryset
